Skip to content

Add backend-keyed to_backend; make cuda/rocm aliases#302

Merged
cmhamel merged 1 commit into
mainfrom
add-to-backend
May 27, 2026
Merged

Add backend-keyed to_backend; make cuda/rocm aliases#302
cmhamel merged 1 commit into
mainfrom
add-to-backend

Conversation

@lxmota
Copy link
Copy Markdown
Contributor

@lxmota lxmota commented May 22, 2026

Introduce to_backend(backend::KA.Backend, x) — moves x onto a given
KernelAbstractions backend. CPU is identity (CPU-built data already lives
on the CPU backend); CUDABackend/ROCBackend are provided by the CUDA and
AMDGPU package extensions. An unknown backend errors with a hint to load
the corresponding GPU package.

This lets downstream packages select a device by passing a KA.Backend
object, instead of depending on CUDA.jl/AMDGPU.jl directly and calling
the named cuda()/rocm() functions.

cuda(x) and rocm(x) are kept as back-compat aliases that delegate to
to_backend. FEC test suite passes.

Introduce `to_backend(backend::KA.Backend, x)` — moves `x` onto a given
KernelAbstractions backend. CPU is identity (CPU-built data already lives
on the CPU backend); CUDABackend/ROCBackend are provided by the CUDA and
AMDGPU package extensions. An unknown backend errors with a hint to load
the corresponding GPU package.

This lets downstream packages select a device by passing a KA.Backend
object, instead of depending on CUDA.jl/AMDGPU.jl directly and calling
the named cuda()/rocm() functions.

cuda(x) and rocm(x) are kept as back-compat aliases that delegate to
to_backend. FEC test suite passes.
@lxmota lxmota requested a review from cmhamel May 22, 2026 02:53
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.33%. Comparing base (d1fec2d) to head (9788820).

Files with missing lines Patch % Lines
ext/CUDAExt.jl 0.00% 2 Missing ⚠️
src/FiniteElementContainers.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
+ Coverage   55.00%   61.33%   +6.32%     
==========================================
  Files          55       55              
  Lines        4801     4811      +10     
==========================================
+ Hits         2641     2951     +310     
+ Misses       2160     1860     -300     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# Move `x` onto the given KernelAbstractions backend. CPU is identity —
# CPU-built data already lives on the CPU backend. GPU backends (CUDABackend,
# ROCBackend) are provided by the CUDA / AMDGPU package extensions.
to_backend(::KA.CPU, x) = x
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only suggestion here is that in the future we add an additional method to_host(x) = to_backend(KA.CPU(), x)

@cmhamel cmhamel merged commit 3369709 into main May 27, 2026
10 of 15 checks passed
@cmhamel cmhamel deleted the add-to-backend branch May 27, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants